#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>
#include <queue>

using namespace std;
using PII = pair<int, int>;
using LL = long long;
const int N = 2020;

int n;
bool g[N][N];
bool st[N][N];
PII qu[N * N * 4];
int res = 0;

int dis[6][2] = {{-1, -1}, {-1, 0}, {0, -1}, {0, 1}, {1, 0}, {1, 1}};

void bfs(int x, int y){
    int hh = 0, tt = 0;
    qu[tt++] = {x, y};
    st[x][y] = true;
    while(hh < tt){
        PII temp = qu[hh++];

        int x1 = temp.first, y1 = temp.second;
        st[x1][y1] = true;

        for(int i = 0; i < 6; i ++){
            int nx = x1 + dis[i][0], ny = y1 + dis[i][1];
            if(nx < 0 || nx > 2000 || ny < 0 || ny > 2000) continue;
            if(!g[nx][ny] || st[nx][ny]) continue;
            st[nx][ny] = true;
            qu[tt++] = {nx, ny};
        }
    }
}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);


    scanf("%d", &n);

    int a, b;
    for(int i = 1; i <= n; i ++){
        scanf("%d%d", &a, &b);
        a += 1000;
        b += 1000;  
        g[a][b] = true;
    }

    for(int i = 0; i <= 2000; i ++){
        for(int j = 0; j <= 2000; j ++){
            if(g[i][j] && !st[i][j]){
                bfs(i, j);
                res ++;
            }
        }
    }

    cout << res << '\n';


    return 0;
}